//
//  CognitiveReset.swift
//  HIextractLicve
//
//  Created by HIextractLicve on 2024/12/12.
//

import UIKit
import MJRefresh

class CognitiveReset: UIViewController {
    var mindfulness:Set<Int>?
    var suggestion:Set<String>?
    
    var eachVioViewHTLC:THLCNOrBUTTOn?
    var mindfulnessPageHTL:THLCNPageControll?
    var journeyHTLC:UIView?

    
    var  professionals:Set<CGFloat>?
    var exchangeHTLC:[String:Array<Dictionary<String,String>>]?

    var maingkingNOwRoomDAtaHTLC:Array<Dictionary<String,String>>{
      
        
        if hreingpickTager == 0 {
           
         
            return HTLCAllDealRelaxing.Relaxing.fancliistHTL.0
        }else  if hreingpickTager == 1 {
           
            return HTLCAllDealRelaxing.Relaxing.focussuuserHTL.0
        }else  {
           
            return HTLCAllDealRelaxing.Relaxing.fancliistHTL.0
        }
    }
    
    
    var hreingpickTager:Int
    init(stressdescHTL:Set<Int>,HtlPoiu: Int) {
        self.hreingpickTager = HtlPoiu
        super.init(nibName: nil, bundle: nil)
        mindfulness = stressdescHTL
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var builCollectionLiveViewHTL: UICollectionView = {
        let coijfLayout = UICollectionViewFlowLayout.init()
        coijfLayout.itemSize = CGSize.init(width: (UIScreen.main.bounds.width - 24), height:80)
        
        coijfLayout.minimumInteritemSpacing = 30
        coijfLayout.scrollDirection = .vertical
        coijfLayout.minimumLineSpacing = 30
        
        
        let fiettCol = UICollectionView.init(frame: .zero, collectionViewLayout: coijfLayout)
     
        fiettCol.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "HTLCUselistListCell")
        
        if self.navigationController?.navigationBar.isHidden == true {
            journeyHTLC?.alpha = 1
            journeyHTLC?.layer.cornerRadius = 12
        }
        journeyHTLC?.backgroundColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)

        eachVioViewHTLC = THLCNOrBUTTOn.init()
        eachVioViewHTLC?.setTitle("anchors", for: .normal)
        if journeyHTLC != nil {
            journeyHTLC?.addSubview(eachVioViewHTLC ?? THLCNOrBUTTOn.init())
            view.addSubview(journeyHTLC!)
        }

        mindfulnessPageHTL = THLCNPageControll()
        mindfulnessPageHTL?.numberOfPages = 1
        mindfulnessPageHTL?.backgroundColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)
        mindfulnessPageHTL?.tintColor = UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 0.01)
        mindfulnessPageHTL?.sizeToFit()

        if journeyHTLC != nil {
            journeyHTLC?.addSubview(mindfulnessPageHTL ?? THLCNPageControll.init())
           
        }
       
            fiettCol.showsVerticalScrollIndicator = false
        
        fiettCol.delegate = self
        fiettCol.dataSource = self
       
        fiettCol.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
       fiettCol.showsVerticalScrollIndicator = false
       
        fiettCol.backgroundColor = .clear
        fiettCol.dataSource = self
        fiettCol.mj_header = MJRefreshNormalHeader(refreshingBlock: {
            
            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                fiettCol.reloadData()
               
                    fiettCol.mj_header?.endRefreshing()
                
                
            }
            
        })
        return fiettCol
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor =  UIColor(red: 0.06, green: 0.07, blue: 0.07, alpha: 1)
        
        let abacjkbroHTLC = UIButton.init()
        abacjkbroHTLC.addTarget(self, action: #selector(diBakissBoockHTLC), for: .touchUpInside)
        abacjkbroHTLC.setImage(UIImage.init(named: "graybackjHTL"), for: .normal)
      
        
        let titkelHTLC = UILabel.init()
        titkelHTLC.text = hreingpickTager == 0 ? HTLROOOMMeasg.BinrwetioBase64("RmFucw==") : HTLROOOMMeasg.BinrwetioBase64("Rm9sbG93")
        titkelHTLC.textColor = .white
        titkelHTLC.font =  UIFont(name: "Trebuchet MS Bold", size: 14)
        titkelHTLC.textAlignment = .center
        
        view.addSubview(abacjkbroHTLC)
        view.addSubview(titkelHTLC)
        view.addSubview(builCollectionLiveViewHTL)
        abacjkbroHTLC.snp.makeConstraints { make in
            make.width.height.equalTo(32)
            make.leading.equalToSuperview().offset(12)
            make.top.equalToSuperview().offset(saaffeeTppoHightHTL + 8)
        }
        titkelHTLC.snp.makeConstraints { make in
            make.centerY.equalTo(abacjkbroHTLC)
            make.centerX.equalToSuperview()
        }
        
        builCollectionLiveViewHTL.snp.makeConstraints { make in
            make.leading.trailing.bottom.equalToSuperview()
            make.top.equalTo(abacjkbroHTLC.snp.bottom).offset(21)
        }
        
       
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        builCollectionLiveViewHTL.mj_header?.beginRefreshing()
    }
    
    @objc func diBakissBoockHTLC() {
       self.navigationController?.popToRootViewController(animated: true)
    }
}


extension CognitiveReset:UICollectionViewDelegate,UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
      
       
        return maingkingNOwRoomDAtaHTLC.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cceggggg = collectionView.dequeueReusableCell(withReuseIdentifier: "HTLCUselistListCell", for: indexPath)
        
        let passonHtlacData = maingkingNOwRoomDAtaHTLC[indexPath.row]
        
        if let tagimage = cceggggg.viewWithTag(20) as? UIImageView {
            tagimage.image = UIImage.init(named: passonHtlacData["HTLCAvater"] ?? "")
        }else{
            let imgHeader = UIImageView.init(image: UIImage.init(named: passonHtlacData["HTLCAvater"] ?? ""))
            imgHeader.layer.cornerRadius = 35
            imgHeader.layer.masksToBounds  = true
            imgHeader.contentMode = .scaleAspectFill
            imgHeader.tag = 20
            cceggggg.addSubview(imgHeader)
            imgHeader.snp.makeConstraints { make in
                make.left.equalToSuperview().offset(16.xHTL)
                make.centerY.equalToSuperview()
                make.width.height.equalTo(70)
            }
        }
        
        if let traingoimgmage = cceggggg.viewWithTag(40) as? UIImageView {
            traingoimgmage.image = UIImage.init(named: "fiiiOnower")
        }else{
            let imgHeader = UIImageView.init(image: UIImage.init(named: "fiiiOnower"))
  
          
            imgHeader.tag = 40
            cceggggg.addSubview(imgHeader)
            imgHeader.snp.makeConstraints { make in
                make.trailing.equalToSuperview().inset(20.xHTL)
                make.centerY.equalToSuperview()
                make.width.height.equalTo(22)
            }
        }
        
        if let taglblbdeNaee = cceggggg.viewWithTag(30) as? UILabel {
            taglblbdeNaee.text =  passonHtlacData["HTLCkiName"]
        }else{
            let imgHeader = UILabel.init()
            imgHeader.textAlignment = .left
            imgHeader.textColor = .white
            imgHeader.font = UIFont(name: "Trebuchet MS Bold", size: 16)
            imgHeader.tag = 30
            cceggggg.addSubview(imgHeader)
            imgHeader.snp.makeConstraints { make in
                make.leading.equalTo(cceggggg).offset(104)
                make.centerY.equalToSuperview()
                make.trailing.equalToSuperview()
            }
        }
        
        return cceggggg
        
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let passonHtlacData = maingkingNOwRoomDAtaHTLC[indexPath.row]
        var huihuo = 43
        huihuo += 1
        var pagenorHTLC = 23
        pagenorHTLC -= 2
        let community:Set<Int> = [huihuo,pagenorHTLC]
        let enterlive = NnnerCalmtrn.init(stressdescHTL: community, passonHtlacData: passonHtlacData)
        self.navigationController?.pushViewController(enterlive, animated: true)
    }
    
    
}
